import { Channels } from '@/types/data'
import { ChannelAction } from '@/types/store'

type State = {
  allChannels: Channels,
  userChannels: Channels,
  active: string // 当前选中的频道的id
}
// 初始值
const initState = {
  allChannels: [], // 所有的频道
  userChannels: [], // 用户的频道
  active: '0'
} as State
console.log(initState)
export default function channel (state = initState, action: ChannelAction) {
  console.log(action)
  if (action.type === 'channel/getChannel') {
    return { ...state, userChannels: action.payload }
  } else if (action.type === 'channel/changeActive') {
    return { ...state, active: action.payload }
  } else if (action.type === 'channel/saveAllChannels') {
    return { ...state, allChannels: action.payload }
  } else { return state }
}
